<?php

use yii\helpers\Url;
use yii\helpers\Html;

?>

<?= $this->render('_nav') ?>
<style>
    .thumbnail {
        display: inline-block;
    }
</style>

<div>
    <h2>展示已上传图片素材</h2>
    <?= Html::beginForm(['source-img'], 'post'); ?>
    <div class="form-group col-sm-6">
        <label >Offset <span class="text-muted">(从全部素材的该偏移位置开始返回，0表示从第一个素材 返回)</span></label>
        <input type="number" class="form-control" placeholder="Offset" name="offset" value="0">
    </div>
    <div class="form-group col-sm-6">
        <label >Count <span class="text-muted">(返回素材的数量，取值在1到20之间)</span></label>
        <input type="number" class="form-control" placeholder="Count" name="count" value="20">
    </div>
    <div class="form-group">
        <button type="submit" class="btn btn-default">展示</button>
    </div>
    <?= Html::endForm(); ?>

    <?php if (isset($items)) { ?>
        <div class="row">
        <?= isset($total_count) ? '<p class="text-info">图片素材总数为： ' . $total_count . '</p>' : ''; ?>
        </div>
        
        <div class="row">
            <div>
                <?php foreach($items as $v){ ?>
                    <a href="<?= $v['url'] ?>" class="thumbnail" target="_blank">
                        <img src="<?= $v['url'] ?>" alt="<?= $v['name'] ?>" style="width:140px;height:140px;">
                    </a>
                <?php } ?>
            </div>
        </div>
    <?php } ?>
</div>

<hr>

<div>
    <h2>上传图片素材</h2>
    <?= Html::beginForm(['upload-img'], 
        'post', ['enctype' => 'multipart/form-data']); ?>
    <div class="form-group">
        <label>图片</label>
        <input type="file" name="file">
    </div>
    <div class="form-group">
        <button type="submit" class="btn btn-default">上传</button>
    </div>
    <?= Html::endForm(); ?>
</div>